
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/cdev.h>


MODULE_AUTHOR("mdy");
MODULE_DESCRIPTION("demo");
MODULE_LICENSE("GPL");

struct timer_dev
{
    struct cdev c_dev;
    struct timer_list my_timer;
    int my_value;
};

static struct timer_dev td1;
static struct timer_dev td2;

static void MyTimerCallback(struct timer_list *t)
{
    struct timer_dev *dev = from_timer(dev, t, my_timer);
    printk("my_value = %d, jiffies = %ld\n", dev->my_value, jiffies);
    del_timer(t);
}

static int __init timer_demo_init(void)
{
    td1.my_value = 123456;
    td2.my_value = 789012;

    timer_setup(&td1.my_timer, MyTimerCallback, 0);
    td1.my_timer.expires = jiffies + 1 * HZ;
    add_timer(&td1.my_timer);

    timer_setup(&td2.my_timer, MyTimerCallback, 0);
    td2.my_timer.expires = jiffies + 2 * HZ;
    add_timer(&td2.my_timer);

    return 0;
}

static void __exit timer_demo_exit(void)
{
    return;
}
 
module_init(timer_demo_init);
module_exit(timer_demo_exit);

